#!/usr/bin/env python
# -*- coding:utf-8 -*-

""" Function library can be call be other python script
"""


from urlparse import urlparse


def parse_params(str_url):
    """ parse url to parameters dictionary
    :param str_url:
    :return:
    """
    params_dict = dict()
    url_params = urlparse(str_url)
    str_params = str_url.split('?')[1]
    for param_item in str_params.split('&'):
        kvs = param_item.split('=')
        params_dict[kvs[0]] = kvs[1]
    params_dict['host'] = url_params.hostname
    return params_dict


def parse_cookies(req_cookie_jar):
    """ transfer req_cookie_jar to dict
    :param req_cookie_jar:
    :return:
    """
    cookie_dict = dict()
    for k in req_cookie_jar.keys():
        cookie_dict[k] = req_cookie_jar[k]
    return cookie_dict


if __name__ == '__main__':
    print parse_params('http://www.jandown.com/link.php?ref=PDR4ZIzDaI')